window.onload = function(){
	var api = 'http://h6.duchengjiu.top/shop/';
	(function(){
		var oSdxjs = document.getElementById('sdxjs');
		//var templateStr = document.getElementById('sd-aa').innerHTML;
		//console.log(templateStr);
		$.get(api +'api_cat.php',{},function(data){
			//console.log(data);
			var obj = data.data;
			//console.log(obj);
			var str = '';
			//console.log(tempile);
			for(var i=0;i<obj.length;i++){
				//var tempile = _.template(templateStr);
				str += "<dl><dt><img src='img/23687.png'/></dt><dd><a href='classify.html?cat_id="+obj[i].cat_id+"'>"+obj[i].cat_name+"</a></dd></dl>"
			};
			oSdxjs.innerHTML = str;
		});
		
	})();
	
	//登录问题
	(function(){
		var localName = localStorage.getItem('username');
		
		var oLogin = document.getElementById('login');
		var oRegister = document.getElementById('register');
		var oWelcome = document.getElementById('welcome');
		var oQuit = document.getElementById('quit');
		var oCart = document.getElementById('cart');
		if(localName){
			oLogin.style.display = 'none';
			oRegister.style.display = 'none';
			oWelcome.style.display = 'block';
			oQuit.style.display = 'block';
			oWelcome.innerHTML += localName;
			
		}else{
			oLogin.style.display = 'block';
			oRegister.style.display = 'block';
			oWelcome.style.display = 'none';
			oQuit.style.display = 'none';
		};
		
		//点击退出按钮
		oQuit.onclick = function(){
			oLogin.style.display = 'block';
			oRegister.style.display = 'block';
			oWelcome.style.display = 'none';
			oQuit.style.display = 'none';
			localStorage.removeItem('username');
			localStorage.removeItem('token');
		};
		
		//点击购物车分情况
		oCart.onclick = function(){
			if(localName){
				location.href = 'cart.html';
			}else{
				alert('抱歉,您还没有登录,请先登录!');
				location.href = 'login.html';
			};
		};
	})();
	
	
};
//
//
//
//
//
//
//
//
//
//
//

//
//
//
//